package com.kidedu.util;

import java.io.FileOutputStream;
import java.io.OutputStream;

import sun.misc.BASE64Decoder;

public class Base64ToImg {

 
    public static boolean GenerateImage(String imgStr)  
    {  
        if (imgStr == null) 
            return false;  
        BASE64Decoder decoder = new BASE64Decoder();  
        try   
        {  
            byte[] b = decoder.decodeBuffer(imgStr);  
            for(int i=0;i<b.length;++i)  
            {  
                if(b[i]<0)  
                {
                    b[i]+=256;  
                }  
            }  
            String imgFilePath = "d://222.png";
            OutputStream out = new FileOutputStream(imgFilePath);      
            out.write(b);  
            out.flush();  
            out.close();  
            return true;  
        }   
        catch (Exception e)   
        {  
            return false;  
        }  
    }  
    
}
